package com.kmproject.haifu.mvp.ui.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.flyco.roundview.RoundLinearLayout;
import com.kmproject.haifu.R;
import com.kmproject.haifu.mvp.model.entity.beans.HousePayWayBean;

import java.util.List;

public class RechargeAmountAdapter extends BaseQuickAdapter<HousePayWayBean, BaseViewHolder> {
    private Context mContext;
    private String selectedId = "";

    public RechargeAmountAdapter(@Nullable List<HousePayWayBean> data, Context context) {
        super(R.layout.item_recharge_amount, data);
        mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, HousePayWayBean item) {
        RoundLinearLayout rll_recharge_amount = helper.getView(R.id.rll_recharge_amount);
        TextView tv_price = helper.getView(R.id.tv_price);

        if (selectedId.equals(item.getDictId())) {
            setSelectedView(true, rll_recharge_amount, tv_price);
        } else {
            setSelectedView(false, rll_recharge_amount, tv_price);
        }

//        tv_price.setText(String.format(mContext.getString(R.string.recharge_center_amount_fm), item.getAliasName()));
        tv_price.setText(item.getAliasName());
        helper.setText(R.id.tv_recharge_amount, item.getName());
    }

    private void setSelectedView(boolean isSelected, RoundLinearLayout roundLinearLayout, TextView textView) {
        if (isSelected) {
            roundLinearLayout.getDelegate().setBackgroundColor(ContextCompat.getColor(mContext, R.color.color_F5D7D3));
            roundLinearLayout.getDelegate().setBackgroundPressColor(ContextCompat.getColor(mContext, R.color.color_F5D7D3));
            roundLinearLayout.getDelegate().setStrokeColor(ContextCompat.getColor(mContext, R.color.color_ff3a3a));
            textView.setTextColor(ContextCompat.getColor(mContext, R.color.color_EB5D4F));
        } else {
            roundLinearLayout.getDelegate().setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
            roundLinearLayout.getDelegate().setBackgroundPressColor(ContextCompat.getColor(mContext, R.color.white));
            roundLinearLayout.getDelegate().setStrokeColor(ContextCompat.getColor(mContext, R.color.color_AAAAAA));
            textView.setTextColor(ContextCompat.getColor(mContext, R.color.common_title_text));
        }
    }

    public void setSelectedId(String selectedId) {
        this.selectedId = selectedId;
    }
}
